from fabric.api import *
import sys

names = ['yu.huang']

def create_user(group='ubuntu'):
    for name in names:
        if name:
            with settings(warn_only=True): 
                sudo('userdel ' + name)
                sudo('rm -rf /home/' + name)
        sudo('useradd -m ' + name)
        sudo('adduser ' + name + ' ' + group)
        #sudo('adduser ' + name + ' sudo')
        sudo('echo ' + name + ':1qaz2wsx | chpasswd')
        sudo('chsh -s /bin/bash ' + name)
        sudo('chage -d 0 ' + name)

def change_user_password():
    for name in names:
        if name:
            sudo('echo ' + name + ':Sunday.2016 | chpasswd')        

if __name__ == "__main__":
    env.hosts = [
        'ubuntu@54.223.57.202'
    ]
    env.key_filename = '../sc-admin.pem'
    execute(create_user)    
    #execute(change_user_password)
